package com.lidy.tankbattle.threaduse;

/**
 * @author lidy
 * @version V1.0
 * @classname MyThread
 * @description TODO
 * @date 2022/5/29 11:32
 */
public class MyThread {
    public static void main(String[] args) throws InterruptedException {
        Cat cat = new Cat();
        for (int i = 0; i < 10; i++) {
            if (i == 5) {
                cat.start();
                cat.join();
            }
            System.out.println("hi" + i + "-" + Thread.currentThread().getName());

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

class Cat extends Thread {
    int times = 0;

    @Override
    public void run() {
        while (true) {
            times++;
            System.out.println("Hello" + times + "-" + Thread.currentThread().getName());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (times == 10) {
                break;
            }
        }

    }
}

